package com.dhcc.bpm.modules.safe.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhcc.bpm.common.text.Convert;
import com.dhcc.bpm.modules.safe.entity.GateControl;
import com.dhcc.bpm.modules.safe.mapper.GateControlMapper;
import com.dhcc.bpm.modules.safe.service.IGateControlService;
import com.dhcc.bpm.modules.safe.vo.GateControlVO;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName GateControlServiceImpl
 * @Description 访问控制网关关联表 服务实现类
 * @Author daina
 * @Date 2020/2/21 14:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@Service("opc_gate_control")
public class GateControlServiceImpl extends ServiceImpl<GateControlMapper, GateControl> implements IGateControlService {

	@Autowired
	private GateControlMapper gateControlMapper;
	@Override
	public IPage<GateControlVO> selectGateControlPage(IPage<GateControlVO> page, GateControlVO gateControl) {
		return page.setRecords(baseMapper.selectGateControlPage(page, gateControl));
	}

	@Override
	public Boolean batchControllerGate(Long opcControlId, String ids) {
		List<Long> gateIds = Func.toLongList(ids);
		ArrayList<GateControl> list = new ArrayList<>();
		gateIds.forEach(gateId->{
			GateControl gateControl = new GateControl();
			gateControl.setOpcGatewayId(gateId);
			gateControl.setOpcControlId(opcControlId);
			list.add(gateControl);
		});
		return saveBatch(list);
	}

	@Override
	public int deleteGateways(Long opcControlId, String ids) {
		return gateControlMapper.deleteGateways(opcControlId,Convert.toLongArray(ids));
	}

}
